<?php

namespace fztadmin\modules\user\models\forms;

use common\components\fenzhangtong\FenZhangTong;
use common\queues\LogFengZhangTongSend;
use common\Tools;

class Custom extends \common\models\db\Custom
{
    const SCENARIO_UPDATE_PAY_PASSWORD = 'update-pay-password';

    const BIZ_TYPE_1 = '1';
    const BIZ_TYPE_2 = '2';
    const BIZ_TYPE_3 = '3';

    public function getBizTypeDesc()
    {
        return [
            self::BIZ_TYPE_1 => "修改密码",
            self::BIZ_TYPE_2 => "重置密码",
            self::BIZ_TYPE_3 => "首次设置密码",
        ];
    }

    public $bizType;

    public function updateMobile(FenZhangTong &$fzt)
    {
        $transId = uniqid();
        $params = [
            'transId' => $transId,
            'platCustNo' => $this->plat_cust_no,
            'notifyUrl' => \Yii::$app->apiTool->generateUrl("/notify/fzt-custom-update-mobile", []), // 通知回调地址
            'returnUrl' => \Yii::$app->apiTool->generateUrl("/notify/fzt-custom-update-mobile", [
                'redirect_url' => urlencode(\Yii::$app->urlManager->createAbsoluteUrl(["/user/center/update-local-mobile", 'custom_id' => $this->id])),
            ]), // 交易完成后页面跳转地址
        ];
        $fzt->IESI111104($params);
        $log = new LogFengZhangTongSend();
        $log->fzt = $fzt;
        $log->forModelClass = CustomBankCard::class;
        $log->forModelId = $this->id;
        \Yii::$app->queue->push($log);
        switch ($fzt->ret_code){
            case "00000":
                return true;
                break;
//            case "E010110105":
//                \Yii::$app->session->addFlash("error", $fzt->ret_msg);
//                \Yii::$app->queue->push(new CustomSetSettlementCard(['customBankCardId' => $this->id]));
//                $fzt->resp_arr['retUrl'] = \Yii::$app->urlManager->createAbsoluteUrl("/site/index");
//                return true;
//                break;
            default:
                \Yii::$app->session->addFlash("error", "请求分账通异常：".Tools::toJson($fzt->resp_arr));
                return false;
                break;
        }
    }

    public function updatePayPassword(FenZhangTong &$fzt)
    {
        $transId = uniqid();
        $params = [
            'transId' => $transId,
            'platCustNo' => $this->plat_cust_no,
            'bizType' => self::BIZ_TYPE_1,
            'notifyUrl' => \Yii::$app->apiTool->generateUrl("/notify/fzt-custom-update-pay-password", []), // 通知回调地址
            'returnUrl' => \Yii::$app->apiTool->generateUrl("/notify/fzt-custom-update-pay-password", [
                'redirect_url' => urlencode(\Yii::$app->urlManager->createAbsoluteUrl(["/site/index"])),
            ]), // 交易完成后页面跳转地址
        ];
        $fzt->IESI111006($params);
        $log = new LogFengZhangTongSend();
        $log->fzt = $fzt;
        $log->forModelClass = CustomBankCard::class;
        $log->forModelId = $this->id;
        \Yii::$app->queue->push($log);
        switch ($fzt->ret_code){
            case "00000":
                return true;
                break;
//            case "E010110105":
//                \Yii::$app->session->addFlash("error", $fzt->ret_msg);
//                \Yii::$app->queue->push(new CustomSetSettlementCard(['customBankCardId' => $this->id]));
//                $fzt->resp_arr['retUrl'] = \Yii::$app->urlManager->createAbsoluteUrl("/site/index");
//                return true;
//                break;
            default:
                \Yii::$app->session->addFlash("error", "请求分账通异常：".Tools::toJson($fzt->resp_arr));
                return false;
                break;
        }
    }
}